//促销控制器
var PromotionIndexCtrl = ['$rootScope', '$scope', '$location', 'ngDialog', 'Promotion', 'GoodsCart', function ($rootScope, $scope, $location, ngDialog, Promotion, GoodsCart) {
        var window_id;

        //购物车列表
        if (!$rootScope.goods_cart) {
            GoodsCart.init();
        }
        var _select_promotions = [];
        $rootScope.goods_cart.select_promotions.forEach(function (e) {
            _select_promotions.push(e.promotion_rule_id);
        });
        
        Promotion.list().then(function () {
            $scope.list = [];
            var s = {};

            $.each($rootScope.goods_cart.today_promotions, function (i, n) {
                s = {};
                Promotion.getPromotionOptions_by_promo_id(n.promotion_rule_id).then(function(ret){
                    s = n;
					s.vip_price = ret[0].vip_price;
					s.customer_price = ret[0].customer_price;
					s.customer_num = ret[0].customer_num;
					s.reduce_price = ret[0].reduce_price;
					s.gift_total_price = ret[0].gift_total_price;
					s.gift_total_num = ret[0].gift_total_num;
					s.rebate = ret[0].rebate;
					s.promotion_rule_id = n.promotion_rule_id;
	                s.class = 'hot';
	                s.desc = n.remark;
	                s.time = n.end_time;
	               
	                
	
	                if (-1 != _select_promotions.indexOf(n.promotion_rule_id)) {
	                    s.class = 'select hot';
	                }
	                $scope.list.push(s);
				});  
            });
        });
        $scope.viewDetail = function (detail) {
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/promotion/prom_detail.html',
                disableAnimation: true,
                scope: $scope,
                trapFocus: false,
                controller: ['$scope', function ($scope) {
                        $scope.detail = detail;
                    }]
            });
        };
    }];
PromotionIndexCtrl.$injector = ['$rootScope', '$scope', '$location', 'ngDialog', 'Promotion', 'GoodsCart'];
